package com.unittec.drainage.provider.manage.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.unittec.drainage.provider.excel.export.ExportExcelColumn;
import com.unittec.drainage.provider.excel.export.ExportExcelUtil;
import com.unittec.drainage.provider.log.Log;
import com.unittec.drainage.provider.manage.service.WaterheadFeeCollectionService;
import com.unittec.drainage.provider.utils.ValidationUtils;
import com.unittec.drainage.sdk.log.enums.LogOperateEnum;
import com.unittec.drainage.sdk.log.enums.LogStatusEnum;
import com.unittec.drainage.sdk.manage.enums.*;
import com.unittec.drainage.sdk.manage.request.*;
import com.unittec.drainage.sdk.manage.response.*;
import com.unittec.drainage.sdk.root.domain.GatewayRequest;
import com.unittec.drainage.sdk.root.domain.Result;
import com.unittec.drainage.sdk.root.enums.BizCode;
import com.unittec.drainage.sdk.root.enums.BizCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 污水费控管理
 *
 * @author wangyongfeng
 * @date 2021/8/18
 */
@RestController
@Api(tags = "污水费管理")
public class WaterheadFeeCollectionController {

    @Autowired
    private Log log;

    @Resource
    private WaterheadFeeCollectionService waterheadFeeCollectionService;

    //污水费应收新增
    @RequestMapping(value = "/301106", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费应收新增", notes = "污水费应收新增")
    public Result<Res301106> addWaterheadReceivable(@RequestBody GatewayRequest<Req301106> req) {
        log.debug(req, "addWaterheadReceivable {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301106 res301106 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            waterheadFeeCollectionService.addWaterheadReceivable(req.getContent());
            res301106 = new Res301106();
            res301106.setIsSuccess(true);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301106", JSON.toJSONString(req), "污水费应收新增", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "addWaterheadReceivable {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301106", JSON.toJSONString(req), "污水费应收新增", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301106);
        } else {
            log.addOperateLog("301106", JSON.toJSONString(req), "污水费应收新增", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }
    
    //污水费应收编辑
    @RequestMapping(value = "/301107", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费应收编辑", notes = "污水费应收编辑")
    public Result<Res301107> updateWaterheadReceivable(@RequestBody GatewayRequest<Req301107> req) {
        log.debug(req, "updateWaterheadReceivable {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301107 res301107 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            waterheadFeeCollectionService.updateWaterheadReceivable(req.getContent());
            res301107 = new Res301107();
            res301107.setIsSuccess(true);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301107", JSON.toJSONString(req), "污水费应收编辑", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "updateWaterheadReceivable {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301107", JSON.toJSONString(req), "污水费应收编辑", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301107);
        } else {
            log.addOperateLog("301107", JSON.toJSONString(req), "污水费应收编辑", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //污水费应收删除
    @RequestMapping(value = "/301108", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费应收删除", notes = "污水费应收删除")
    public Result<Res301108> delWaterheadReceivable(@RequestBody GatewayRequest<Req301108> req) {
        log.debug(req, "delWaterheadReceivable {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301108 res301108 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            waterheadFeeCollectionService.delWaterheadReceivable(req.getContent());
            res301108 = new Res301108();
            res301108.setIsSuccess(true);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301108", JSON.toJSONString(req), "污水费应收删除", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "delWaterheadReceivable {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301108", JSON.toJSONString(req), "污水费应收删除", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301108);
        } else {
            log.addOperateLog("301108", JSON.toJSONString(req), "污水费应收删除", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //污水费应收导出
    @RequestMapping(value = "/301109", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费应收导出", notes = "污水费应收导出")
    public Result<?> exportWaterheadReceivableExcel(@RequestBody GatewayRequest<Req301109> req, HttpServletResponse response) {
        log.debug(req, "exportWaterheadReceivableExcel {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        try {
            ValidationUtils.validateEntityStr(req.getContent());

            //获取需要转出的excel表头的map字段
            List<ExportExcelColumn> headers = new ArrayList<>();
            headers.add(new ExportExcelColumn("receivable_month","应收月份"));
            headers.add(new ExportExcelColumn("receivable_date","应收日期"));
            headers.add(new ExportExcelColumn("user_code","用户代码"));
            headers.add(new ExportExcelColumn("user_name","用户名称"));
            headers.add(new ExportExcelColumn("user_address","用户地址"));
            headers.add(new ExportExcelColumn("user_phone","联系电话"));
            headers.add(new ExportExcelColumn("levy_mode","征收方式"));
            Map<String, String> ispayMap = new HashMap<>();
            ispayMap.put(WaterFeeCollectionIsPayEnum.is_pay_0.getKey(),WaterFeeCollectionIsPayEnum.is_pay_0.getValue());
            ispayMap.put(WaterFeeCollectionIsPayEnum.is_pay_1.getKey(),WaterFeeCollectionIsPayEnum.is_pay_1.getValue());
            headers.add(new ExportExcelColumn("is_pay","缴费状态",true, ispayMap));
            Map<String, String> waterNatureMap = new HashMap<>(16);
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_1.getKey(), WaterheadUserWaterNatureEnum.water_nature_1.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_2.getKey(), WaterheadUserWaterNatureEnum.water_nature_2.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_3.getKey(), WaterheadUserWaterNatureEnum.water_nature_3.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_4.getKey(), WaterheadUserWaterNatureEnum.water_nature_4.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_5.getKey(), WaterheadUserWaterNatureEnum.water_nature_5.getValue());
            headers.add(new ExportExcelColumn("water_nature","用水性质", true, waterNatureMap));
            Map<String, String> priceCategoryMap = new HashMap<>(16);
            priceCategoryMap.put(WaterheadUserPriceCategoryEnum.price_category_0.getKey(), WaterheadUserPriceCategoryEnum.price_category_0.getValue());
            priceCategoryMap.put(WaterheadUserPriceCategoryEnum.price_category_1.getKey(), WaterheadUserPriceCategoryEnum.price_category_1.getValue());
            headers.add(new ExportExcelColumn("price_category","污水价类别", true, priceCategoryMap));
            headers.add(new ExportExcelColumn("water_consumption","用水量(m³)"));
            headers.add(new ExportExcelColumn("water_discharge","排水量(m³)"));
            headers.add(new ExportExcelColumn("water_price","污水费单价(元/m³)"));
            headers.add(new ExportExcelColumn("water_money","污水费金额(元)"));
            headers.add(new ExportExcelColumn("modify_time","录入时间"));
            headers.add(new ExportExcelColumn("modify_user","录入人员"));
            headers.add(new ExportExcelColumn("receipts_month","实收月份"));
            headers.add(new ExportExcelColumn("receipts_date","实收日期"));

            List<Map<String, Object>> l = waterheadFeeCollectionService.getWaterheadReceivableList(req.getContent());
            new ExportExcelUtil<>().exportExcelForMap("污水费应收列表", headers, l, ExportExcelUtil.EXCEl_FILE_2007, response);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301109", JSON.toJSONString(req), "污水费应收导出", log.buildErrmsg(e),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "exportWaterheadReceivableExcel {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301109", JSON.toJSONString(req), "污水费应收导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req);
        } else {
            log.addOperateLog("301109", JSON.toJSONString(req), "污水费应收导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
        }
        return Result.error(req, bizCodeEnum);
    }

    //污水费应收条件分页查询
    @RequestMapping(value = "/301110", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费应收条件分页查询", notes = "污水费应收条件分页查询")
    public Result<Res301110> getWaterheadReceivablePage(@RequestBody GatewayRequest<Req301110> req) {
        log.debug(req, "getWaterheadReceivablePage {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301110 res301110 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Map<String,Object> all = waterheadFeeCollectionService.getWaterheadReceivablePage(req.getContent());
            res301110 = new Res301110();
            res301110.setAll(all);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301110", JSON.toJSONString(req), "污水费应收条件分页查询", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getWaterheadReceivablePage {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301110", JSON.toJSONString(req), "污水费应收条件分页查询", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301110);
        } else {
            log.addOperateLog("301110", JSON.toJSONString(req), "污水费应收条件分页查询", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //污水费详情
    @RequestMapping(value = "/301123", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费详情", notes = "污水费详情")
    public Result<Res301123> getWaterheadFeeCollectionProInfo(@RequestBody GatewayRequest<Req301123> req) {
        log.debug(req, "getWaterheadFeeCollectionProInfo {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301123 res301123 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = waterheadFeeCollectionService.getWaterheadFeeCollectionProInfo(req.getContent());
            res301123 = new Res301123();
            res301123.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301123", JSON.toJSONString(req), "污水费详情", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getWaterheadFeeCollectionProInfo {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301123", JSON.toJSONString(req), "污水费详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301123);
        } else {
            log.addOperateLog("301123", JSON.toJSONString(req), "污水费详情", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //污水费实收收款
    @RequestMapping(value = "/301111", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费实收收款", notes = "污水费实收收款")
    public Result<Res301111> makeWaterheadFeeCollection(@RequestBody GatewayRequest<Req301111> req) {
        log.debug(req, "makeWaterheadFeeCollection {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301111 res301111 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            waterheadFeeCollectionService.makeWaterheadFeeCollection(req.getContent());
            res301111 = new Res301111();
            res301111.setIsSuccess(true);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301111", JSON.toJSONString(req), "污水费实收收款", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "makeWaterheadFeeCollection {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301111", JSON.toJSONString(req), "污水费实收收款", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301111);
        } else {
            log.addOperateLog("301111", JSON.toJSONString(req), "污水费实收收款", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //污水费实收冲正
    @RequestMapping(value = "/301112", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费实收冲正", notes = "污水费实收冲正")
    public Result<Res301112> rightingWaterheadFeeCollection(@RequestBody GatewayRequest<Req301112> req) {
        log.debug(req, "rightingWaterheadFeeCollection {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301112 res301112 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            waterheadFeeCollectionService.rightingWaterheadFeeCollection(req.getContent());
            res301112 = new Res301112();
            res301112.setIsSuccess(true);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301112", JSON.toJSONString(req), "污水费实收冲正", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "rightingWaterheadFeeCollection {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301112", JSON.toJSONString(req), "污水费实收冲正", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301112);
        } else {
            log.addOperateLog("301112", JSON.toJSONString(req), "污水费实收冲正", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //污水费实收导出
    @RequestMapping(value = "/301113", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费实收导出", notes = "污水费实收导出")
    public Result<?> exportWaterheadReceipstExcel(@RequestBody GatewayRequest<Req301113> req, HttpServletResponse response) {
        log.debug(req, "exportWaterheadReceipstExcel {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        try {
            ValidationUtils.validateEntityStr(req.getContent());

            //获取需要转出的excel表头的map字段
            List<ExportExcelColumn> headers = new ArrayList<>();
            headers.add(new ExportExcelColumn("receivable_month","应收月份"));
            headers.add(new ExportExcelColumn("receivable_date","应收日期"));
            headers.add(new ExportExcelColumn("user_code","用户代码"));
            headers.add(new ExportExcelColumn("user_name","用户名称"));
            headers.add(new ExportExcelColumn("levy_mode","征收方式"));
            Map<String, String> ispayMap = new HashMap<>();
            ispayMap.put("--","--");
            ispayMap.put(WaterFeeCollectionIsPayEnum.is_pay_0.getKey(),WaterFeeCollectionIsPayEnum.is_pay_0.getValue());
            ispayMap.put(WaterFeeCollectionIsPayEnum.is_pay_1.getKey(),WaterFeeCollectionIsPayEnum.is_pay_1.getValue());
            headers.add(new ExportExcelColumn("is_pay","缴费状态",true, ispayMap));
            Map<String, String> priceCategoryMap = new HashMap<>(16);
            priceCategoryMap.put(WaterheadUserPriceCategoryEnum.price_category_0.getKey(), WaterheadUserPriceCategoryEnum.price_category_0.getValue());
            priceCategoryMap.put(WaterheadUserPriceCategoryEnum.price_category_1.getKey(), WaterheadUserPriceCategoryEnum.price_category_1.getValue());
            headers.add(new ExportExcelColumn("price_category","污水价类别", true, priceCategoryMap));
            headers.add(new ExportExcelColumn("water_consumption","用水量(m³)"));
            headers.add(new ExportExcelColumn("water_discharge","排水量(m³)"));
            headers.add(new ExportExcelColumn("water_price","污水费单价(元/m³)"));
            headers.add(new ExportExcelColumn("water_money","污水费金额(元)"));
            headers.add(new ExportExcelColumn("receivable_water_money","应征金额(元)"));
            headers.add(new ExportExcelColumn("receipts_water_money","实征金额(元)"));
            headers.add(new ExportExcelColumn("receipts_month","实收月份"));
            headers.add(new ExportExcelColumn("receipts_date","实收日期"));
            headers.add(new ExportExcelColumn("receipts_name","收费人员"));
            Map<String, String> isrightingMap = new HashMap<>();
            isrightingMap.put(WaterFeeCollectionIsRightingEnum.is_righting_0.getKey(), WaterFeeCollectionIsRightingEnum.is_righting_0.getValue());
            isrightingMap.put(WaterFeeCollectionIsRightingEnum.is_righting_1.getKey(), WaterFeeCollectionIsRightingEnum.is_righting_1.getValue());
            headers.add(new ExportExcelColumn("is_righting","是否冲正", true, isrightingMap));
            headers.add(new ExportExcelColumn("modify_user","操作人员"));
            headers.add(new ExportExcelColumn("op_time","操作时间"));

            List<Map<String, Object>> l = waterheadFeeCollectionService.getWaterheadReceipstList(req.getContent());
            new ExportExcelUtil<>().exportExcelForMap("污水费实收列表", headers, l, ExportExcelUtil.EXCEl_FILE_2007, response);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301113", JSON.toJSONString(req), "污水费实收导出", log.buildErrmsg(e),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "exportWaterheadReceipstExcel {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301113", JSON.toJSONString(req), "污水费实收导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req);
        } else {
            log.addOperateLog("301113", JSON.toJSONString(req), "污水费实收导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
        }
        return Result.error(req, bizCodeEnum);
    }

    //污水费实收条件分页查询
    @RequestMapping(value = "/301114", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费实收条件分页查询", notes = "污水费实收条件分页查询")
    public Result<Res301114> getWaterheadFeeCollectionReceipstPage(@RequestBody GatewayRequest<Req301114> req) {
        log.debug(req, "getWaterheadFeeCollectionReceipstPage {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301114 res301114 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = waterheadFeeCollectionService.getWaterheadFeeCollectionReceipstPage(req.getContent());
            res301114 = new Res301114();
            res301114.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301114", JSON.toJSONString(req), "污水费实收条件分页查询", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getWaterheadFeeCollectionReceipstPage {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301114", JSON.toJSONString(req), "污水费实收条件分页查询", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301114);
        } else {
            log.addOperateLog("301114", JSON.toJSONString(req), "污水费实收条件分页查询", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }
    
    //污水费欠收条件分页查询
    @RequestMapping(value = "/301116", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费欠收条件分页查询", notes = "污水费欠收条件分页查询")
    public Result<Res301116> getWaterheadFeeCollectionArrearsPage(@RequestBody GatewayRequest<Req301116> req) {
        log.debug(req, "getWaterheadFeeCollectionArrearsPage {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301116 res301116 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = waterheadFeeCollectionService.getWaterheadFeeCollectionArrearsPage(req.getContent());
            res301116 = new Res301116();
            res301116.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301116", JSON.toJSONString(req), "污水费欠收条件分页查询", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "getWaterheadFeeCollectionArrearsPage {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301116", JSON.toJSONString(req), "污水费欠收条件分页查询", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301116);
        } else {
            log.addOperateLog("301116", JSON.toJSONString(req), "污水费欠收条件分页查询", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //污水费欠收导出
    @RequestMapping(value = "/301117", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "污水费欠收导出", notes = "污水费欠收导出")
    public Result<?> exportWaterheadArrearsExcel(@RequestBody GatewayRequest<Req301117> req, HttpServletResponse response) {
        log.debug(req, "exportWaterheadArrearsExcel {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        try {
            ValidationUtils.validateEntityStr(req.getContent());

            //获取需要转出的excel表头的map字段
            List<ExportExcelColumn> headers = new ArrayList<>();
            headers.add(new ExportExcelColumn("receivable_month","应收月份"));
            headers.add(new ExportExcelColumn("receivable_date","应收日期"));
            headers.add(new ExportExcelColumn("user_code","用户代码"));
            headers.add(new ExportExcelColumn("user_name","用户名称"));
            headers.add(new ExportExcelColumn("levy_mode","征收方式"));
            Map<String, String> ispayMap = new HashMap<>();
            ispayMap.put(WaterFeeCollectionIsPayEnum.is_pay_0.getKey(),WaterFeeCollectionIsPayEnum.is_pay_0.getValue());
            ispayMap.put(WaterFeeCollectionIsPayEnum.is_pay_1.getKey(),WaterFeeCollectionIsPayEnum.is_pay_1.getValue());
            headers.add(new ExportExcelColumn("is_pay","缴费状态",true, ispayMap));
            Map<String, String> waterNatureMap = new HashMap<>(16);
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_1.getKey(), WaterheadUserWaterNatureEnum.water_nature_1.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_2.getKey(), WaterheadUserWaterNatureEnum.water_nature_2.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_3.getKey(), WaterheadUserWaterNatureEnum.water_nature_3.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_4.getKey(), WaterheadUserWaterNatureEnum.water_nature_4.getValue());
            waterNatureMap.put(WaterheadUserWaterNatureEnum.water_nature_5.getKey(), WaterheadUserWaterNatureEnum.water_nature_5.getValue());
            headers.add(new ExportExcelColumn("water_nature","用水性质", true, waterNatureMap));
            Map<String, String> priceCategoryMap = new HashMap<>(16);
            priceCategoryMap.put(WaterheadUserPriceCategoryEnum.price_category_0.getKey(), WaterheadUserPriceCategoryEnum.price_category_0.getValue());
            priceCategoryMap.put(WaterheadUserPriceCategoryEnum.price_category_1.getKey(), WaterheadUserPriceCategoryEnum.price_category_1.getValue());
            headers.add(new ExportExcelColumn("price_category","污水价类别", true, priceCategoryMap));
            headers.add(new ExportExcelColumn("water_consumption","用水量(m³)"));
            headers.add(new ExportExcelColumn("water_discharge","排水量(m³)"));
            headers.add(new ExportExcelColumn("water_price","污水费单价(元/m³)"));
            headers.add(new ExportExcelColumn("water_money","污水费金额(元)"));
            headers.add(new ExportExcelColumn("create_time","录入时间"));
            headers.add(new ExportExcelColumn("create_user","录入人员"));

            List<Map<String, Object>> l = waterheadFeeCollectionService.getWaterheadArrearsList(req.getContent());
            new ExportExcelUtil<>().exportExcelForMap("污水费欠收列表", headers, l, ExportExcelUtil.EXCEl_FILE_2007, response);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301117", JSON.toJSONString(req), "污水费欠收导出", log.buildErrmsg(e),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "exportWaterheadArrearsExcel {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301117", JSON.toJSONString(req), "污水费欠收导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req);
        } else {
            log.addOperateLog("301117", JSON.toJSONString(req), "污水费欠收导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
        }
        return Result.error(req, bizCodeEnum);
    }

    //月度统计报表
    @RequestMapping(value = "/301118", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "月度统计报表", notes = "月度统计报表")
    public Result<Res301118> monthlyReport(@RequestBody GatewayRequest<Req301118> req) {
        log.debug(req, "monthlyReport {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301118 res301118 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = waterheadFeeCollectionService.monthlyReport(req.getContent());
            res301118 = new Res301118();
            res301118.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301118", JSON.toJSONString(req), "月度统计报表", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "monthlyReport {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301118", JSON.toJSONString(req), "月度统计报表", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301118);
        } else {
            log.addOperateLog("301118", JSON.toJSONString(req), "月度统计报表", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //月度统计报表导出
    @RequestMapping(value = "/301125", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "月度统计报表导出", notes = "月度统计报表导出")
    public Result<?> exportMonthlyReportExcel(@RequestBody GatewayRequest<Req301125> req, HttpServletResponse response) {
        log.debug(req, "exportMonthlyReportExcel {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            //获取需要转出的excel表头的map字段
            List<ExportExcelColumn> headers = new ArrayList<>();
            headers.add(new ExportExcelColumn("user_code","用户代码"));
            headers.add(new ExportExcelColumn("user_name","用户名称"));
            headers.add(new ExportExcelColumn("jan","一月污水费"));
            headers.add(new ExportExcelColumn("feb","二月污水费"));
            headers.add(new ExportExcelColumn("mar","三月污水费"));
            headers.add(new ExportExcelColumn("apr","四月污水费"));
            headers.add(new ExportExcelColumn("may","五月污水费"));
            headers.add(new ExportExcelColumn("june","六月污水费"));
            headers.add(new ExportExcelColumn("july","七月污水费"));
            headers.add(new ExportExcelColumn("aug","八月污水费"));
            headers.add(new ExportExcelColumn("sept","九月污水费"));
            headers.add(new ExportExcelColumn("oct","十月污水费"));
            headers.add(new ExportExcelColumn("nov","十一月污水费"));
            headers.add(new ExportExcelColumn("dece","十二月污水费"));
            List<Map<String, Object>> l = waterheadFeeCollectionService.getMonthlyReportList(req.getContent());
            new ExportExcelUtil<>().exportExcelForMap("月度统计报表", headers, l, ExportExcelUtil.EXCEl_FILE_2007, response);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301125", JSON.toJSONString(req), "月度统计报表导出", log.buildErrmsg(e),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "exportMonthlyReportExcel {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301125", JSON.toJSONString(req), "月度统计报表导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req);
        } else {
            log.addOperateLog("301125", JSON.toJSONString(req), "月度统计报表导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
        }
        return Result.error(req, bizCodeEnum);
    }
    
    //年度统计报表
    @RequestMapping(value = "/301119", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "年度统计报表", notes = "年度统计报表")
    public Result<Res301119> yearlyReport(@RequestBody GatewayRequest<Req301119> req) {
        log.debug(req, "yearlyReport {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        Res301119 res301119 = null;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            Object object = waterheadFeeCollectionService.yearlyReport(req.getContent());
            res301119 = new Res301119();
            res301119.setObject(object);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301119", JSON.toJSONString(req), "年度统计报表", log.buildErrmsg(e),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "yearlyReport {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301119", JSON.toJSONString(req), "年度统计报表", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req, res301119);
        } else {
            log.addOperateLog("301119", JSON.toJSONString(req), "年度统计报表", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_ADD.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, bizCodeEnum);
        }
    }

    //年度统计报表导出
    @RequestMapping(value = "/301126", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "年度统计报表导出", notes = "年度统计报表导出")
    public Result<?> exportYearlyReportExcel(@RequestBody GatewayRequest<Req301126> req, HttpServletResponse response) {
        log.debug(req, "exportYearlyReportExcel {}  ", "begin");
        long startLogTime = System.currentTimeMillis();
        BizCodeEnum bizCodeEnum = BizCode.ERROR;
        try {
            ValidationUtils.validateEntityStr(req.getContent());
            //获取需要转出的excel表头的map字段
            List<ExportExcelColumn> headers = new ArrayList<>();
            headers.add(new ExportExcelColumn("y","年度"));
            headers.add(new ExportExcelColumn("user_number","单位数量"));
            headers.add(new ExportExcelColumn("water_money_total","污水费金额"));
            headers.add(new ExportExcelColumn("receivable_water_money_total","应征金额"));
            headers.add(new ExportExcelColumn("receipts_water_money_total","实征金额"));

            List<Map<String, Object>> l = waterheadFeeCollectionService.getMonthlyReportList(req.getContent());
            new ExportExcelUtil<>().exportExcelForMap("年度统计报表", headers, l, ExportExcelUtil.EXCEl_FILE_2007, response);
            bizCodeEnum = BizCode.SUCCESS;
        } catch (Exception e) {
            log.error(req, e.toString(), e);
            log.addOperateLog("301126", JSON.toJSONString(req), "年度统计报表导出", log.buildErrmsg(e),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
            return Result.error(req, e.getMessage());
        }
        log.debug(req, "exportYearlyReportExcel {}  ", "end");
        if (bizCodeEnum == BizCode.SUCCESS) {
            log.addOperateLog("301126", JSON.toJSONString(req), "年度统计报表导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.SUCCESS.getCode(), startLogTime);
            return Result.success(req);
        } else {
            log.addOperateLog("301126", JSON.toJSONString(req), "年度统计报表导出", bizCodeEnum.getMessage(),
                    LogOperateEnum.LOG_EXPORT.getCode(), LogStatusEnum.ERROR.getCode(), startLogTime);
        }
        return Result.error(req, bizCodeEnum);
    }
    
}
